﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace RedBlackTree
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> words = new FileOperation(Directory.GetCurrentDirectory() + @"\Txt\pride-and-prejudice.txt").readFile();

            Console.WriteLine("Pride and Prejudice");

            Console.WriteLine("Total words: " + words.Count);

            Stopwatch timer = new Stopwatch();
            timer.Start();

            BSTMap<string, int> batmap = new BSTMap<string, int>();
            foreach (var word in words)
            {
                if (batmap.contains(word))
                    batmap.set(word, batmap.get(word) + 1);
                else
                    batmap.add(word, 1);
            }

            Console.WriteLine("Total different words: " + batmap.getSize());
            Console.WriteLine("Frequency of PRIDE: " + batmap.get("pride"));
            Console.WriteLine("Frequency of PREJUDICE: " + batmap.get("prejudice"));
            timer.Stop();
            Console.WriteLine("BSTSet: " + timer.Elapsed.TotalSeconds + " s");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


            timer.Restart();
            timer.Start();

            AVLTree<string, int> avltree = new AVLTree<string, int>();
            foreach (var word in words)
            {
                if (avltree.contains(word))
                    avltree.set(word, avltree.get(word) + 1);
                else
                    avltree.add(word, 1);
            }

            Console.WriteLine("Total different words: " + avltree.getSize());
            Console.WriteLine("Frequency of PRIDE: " + avltree.get("pride"));
            Console.WriteLine("Frequency of PREJUDICE: " + avltree.get("prejudice"));
            timer.Stop();
            Console.WriteLine("AVLTree: " + timer.Elapsed.TotalSeconds + " s");


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();



            timer.Restart();
            timer.Start();

            RBTree<string, int> rbtree = new RBTree<string, int>();
            foreach (var word in words)
            {
                if (rbtree.contains(word))
                    rbtree.set(word, rbtree.get(word) + 1);
                else
                    rbtree.add(word, 1);
            }

            Console.WriteLine("Total different words: " + rbtree.getSize());
            Console.WriteLine("Frequency of PRIDE: " + rbtree.get("pride"));
            Console.WriteLine("Frequency of PREJUDICE: " + rbtree.get("prejudice"));
            timer.Stop();
            Console.WriteLine("RBTree: " + timer.Elapsed.TotalSeconds + " s");

            Console.WriteLine();
        }
    }
}
